home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / gfx / 3d / Skulpt_src.lha / sKulpt-src / Ami-Demo.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-01  |  3.1 KB  |  115 lines

  1. #define STRICT
  2.  
  3. // Includes standard Windows
  4. #include <windows.h>
  5. #include <windowsx.h>
  6. #include <time.h>
  7. #include <stdlib.h>
  8. #include <malloc.h>
  9. #include <memory.h>
  10. #include <stdio.h>
  11.  
  12. // Includes D3D
  13. #define  D3D_OVERLOADS
  14. #include <ddraw.h>
  15. #include <d3d.h>
  16. #include <d3dx.h>
  17.  
  18. // Includes utilitaires D3D
  19. #include "d3dmath.h"
  20. #include "d3dutil.h"
  21. #include "D3DEnum.h"
  22.  
  23. // Ids Resources
  24. #include "resource.h"
  25.  
  26. // Constantes
  27. #include "const.h"
  28.  
  29. // Types
  30. #include "types.h"
  31.  
  32. // Variables globales projet
  33. #include "vars.h"
  34.  
  35. // Prototypes fonctions autres modules
  36. #include "proto.h"
  37.  
  38. // Macros
  39. #include "macros.h"
  40.  
  41. void vDemo(void)
  42. {
  43.     struct DateStamp sDS1, sDS2;
  44.  
  45.     vTrace("TimeDemo 1 - \"Georges's special cheat code\"");
  46.  
  47.     // Supprimer tous les objets courants
  48.     vDeleteObjects();
  49.  
  50.     // Réinitialiser la direction de la caméra
  51.     Target = D3DVECTOR(0., 0., 0.);
  52.  
  53.     // Initialiser les matrices view, proj, world
  54.     hrInitWorld(NULL);
  55.  
  56.     // Créer les  triangles, en material 0 (blanc)
  57.     for (float fZ = -3.; fZ <= 3.; fZ += 0.5)
  58.     {
  59.         D3DVECTOR   v1 = D3DVECTOR( -1. + sin(fZ),    -1. + sin(fZ),    fZ);   // u : 0    v : 0
  60.         D3DVECTOR   v2 = D3DVECTOR(  1. + sin(fZ),    -1. + sin(fZ),    fZ);   // u : 255  v : 0
  61.         D3DVECTOR   v3 = D3DVECTOR(  1. + sin(fZ),     1. + sin(fZ),    fZ);   // u : 255  v : 255
  62.         D3DVECTOR   v4 = D3DVECTOR( -1. + sin(fZ),     1. + sin(fZ),    fZ);   // u : 0    v : 255
  63.         int         i1 = iMakeVertex(v1, XDC_FORCENEW);
  64.         int         i2 = iMakeVertex(v2, XDC_FORCENEW);
  65.         int         i3 = iMakeVertex(v3, XDC_FORCENEW);
  66.         int         i4 = iMakeVertex(v4, XDC_FORCENEW);
  67.  
  68.         int t1 = iMakeTriangle(i1, i2, i3, 0); bSetUV(t1, 0, 0, 127, 0, 127, 127);
  69.         int t2 = iMakeTriangle(i1, i3, i4, 0); bSetUV(t2, 0, 0, 127, 127, 0, 127);
  70.     }
  71.  
  72.     // Forcer le texturage du material 0
  73.     Materials[0].bTextured = TRUE;
  74.     strcpy(Materials[0].sTexName, "wall.ppm");
  75.  
  76.     // Référencer le matériau avec sa texture
  77.     vXRefMaterials2Textures();
  78.  
  79.     // Redessiner la scène 2D complète
  80.     vForce2DRefresh(XDC_MODE_COMPLET);
  81.  
  82.     // Mémoriser l'horodate courante avant animation
  83.     DateStamp(&sDS1);
  84.  
  85.     // Faire tourner la caméra autour du point de visée
  86.     for (float fAlpha = 0 ; fAlpha < 5. * g_PI ; fAlpha += g_PI / 90.)
  87.     {
  88.  
  89.         Observer.x = 9. * sin(fAlpha); // / 1.5);
  90.         Observer.z = 9. * cos(fAlpha);
  91.         Observer.y = -2. + 2. * cos(3. * fAlpha);
  92.  
  93.         D3DUtil_SetViewMatrix(matView,
  94.                   Observer,    // From
  95.                   Target,    // To
  96.                   Target);
  97.  
  98.         // Redessiner la scène 3D
  99.         vForce3DRefresh(XDC_MODE_COMPLET);
  100.  
  101.         // Redessiner la scène 2D en ne forçant que le refresh caméra / curseurs
  102.         vForce2DRefresh(XDC_MODE_PARTIEL);
  103.     }
  104.  
  105.     // Récupérer l'horodate courante après animation et afficher le temps écoulé pendant
  106.     DateStamp(&sDS2);
  107.     if (sDS2.ds_Tick < sDS1.ds_Tick) sDS2.ds_Tick += 3000;
  108.     float fElapsed = (sDS2.ds_Tick - sDS1.ds_Tick) / 50.;
  109.     int iNumFrames = (int) ((5. * g_PI) / (g_PI / 90.)),
  110.         iNumFPS = (int ) (iNumFrames / fElapsed);
  111.  
  112.     vTrace("Temps écoulé : %f s pour %d frames, soit %d fps", fElapsed, iNumFrames, iNumFPS);
  113. }
  114.  
  115.